<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<script type="text/javascript">
	$(function() {
		$("#pager").pager({pagenumber: ${page}, 
			pagecount: ${totalPage},
			buttonClickCallback: function(page){
				$("#content_detail").load("contentList.cms?page="+page);
			}
		});
		$("#content_type_query").val("${contentType}");
		$("#content_Light_query").val("${contentType}");//初始化类别下拉框
		$("#content_poll_query").val("${contentType}");
		
		seeAppType();
	});
	//文本框
	var editor;
	$(function() {
		editor = $("#body")
				.xheditor(
						{
							tools : 'Removeformat,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Align,Emot,Link',
							skin : 'default',
							showBlocktag : false,//段落标签
							internalScript : false,
							internalStyle : false,
							width : 580,
							height : 200,
							fullscreen : false,
							forcePtag : true,
							cleanPaste : 1,
							upMultiple : 1,
							html5Upload : false
							//upImgUrl : "",
							/* upImgExt : 'jpg,jpeg,gif,png',
							onUpload : insertUpload */
						//指定回调函数
						});
		//	$("#seckillcontent").focus();
	});
	//添加content
	function postContent(){
		var contentId=$("#contentId").val();
		var title=$("#title").val();
		var body=$("#body").val();
		var picUrl=$("#picUrl").val();
		var originalPrice=$("#originalPrice").val();
		var nowPrice=$("#nowPrice").val();
		var app = $(":radio[name='RadioGroup'][checked]").val();
		if(app=="01"){
			var contentType=$("#contentType").val();
		}else if(app=="02"){
			var contentType=$("#contentLight").val();
		}else if(app=="03"){
			var contentType=$("#contentPoll").val();
		}
		if(title==""||body==""){
			alert("请填写完整!");
			return;
		}
		if(contentId!=null&&contentId!=""){
			$.ajax({
				type : "POST",
				url : "updateContent.cms",
				data : {
					identifier:contentId,
					contentType : contentType,
					title : title,
					body : body,
					picUrl : picUrl,
					originalPrice:originalPrice,
					nowPrice:nowPrice,
					app:app
					
				},
				success : function() {
					$("#content_detail").load("contentList.cms?page=${page}&contentType=${contentType}");
				}
			});
		}else{
			$.ajax({
				type : "POST",
				url : "postContent.cms",
				data : {
					contentType : contentType,
					title : title,
					body : body,
					picUrl : picUrl,
					originalPrice:originalPrice,
					nowPrice:nowPrice,
					app:app
				},
				success : function() {
					$("#content_detail").load("contentList.cms?page=${page}&contentType=${contentType}");
				}
			});
		}
		
	}
	
	//显示修改
	function showModifyContent(contentId) {
		$.get("getContentById.cms?contentId="+contentId,function(data){
			//alert(data[0].app);
			//$("#contentApp").val(data[0].app);
			$("#btnPostContent").val("修改");
			$("#div_postContent").show();
			$("#contentId").val(data[0].identifier);
			$("#title").val(data[0].title);
			if(data[0].app=="01"){
				$("#contentType").val(data[0].contentType);
			}else if(data[0].app=="02"){
				$("#contentLight").val(data[0].contentType);
			}else if(data[0].app=="03"){
				$("#contentPoll").val(data[0].contentType);
			}
			$("#body").val(data[0].body);
			$("#picUrl").val(data[0].picUrl);
			$("#originalPrice").val(data[0].originalPrice);
			$("#nowPrice").val(data[0].nowPrice);
			$("#tr_originalPrice").show();
			$("#tr_nowPrice").show();
		},'json');
	}
	//上移
	function addContentSort(contentId, sort) {
		$.post("addContentSort.cms?contentId=" + contentId + "&sort=" + sort+"&contentType=${contentType}",
				function() {
					$("#content_detail").load("contentList.cms?page=${page}&contentType=${contentType}&radioApp=${radioApp}");
				});
	}
	//下移
	function downContentSort(contentId, sort) {
		$.post("downContentSort.cms?contentId=" + contentId + "&sort=" + sort+"&contentType=${contentType}",
				function() {
					$("#content_detail").load("contentList.cms?page=${page}&contentType=${contentType}&radioApp=${radioApp}");
				});
	}
	
	function contentUploadImg(){
		var filepath=$("#uploadImgContent").val(); 
		var extStart=filepath.lastIndexOf("."); 
		var ext=filepath.substring(extStart,filepath.length).toUpperCase(); 
		if(ext!=".PNG"&&ext!=".JPG"&&ext!=".JPEG"&&ext!=".GIF"){ 
			alert("图片限于png,jpeg,jpg,gif格式"); 
			return ; 
		}
		$("#content_upload_img_form").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				$("#picUrl").val(data.pictureUrl);
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	
	function delContent(id,sort){
		if(confirm("你确定要删除该项目吗？")){
			$.post("deleteContent.cms?page=${page}&sort="+sort+"&contentType=${contentType}",{
				identifier:id
			},function(data){
				if(data=='success'){
					alert("删除成功！");
					contentPublish();
				}
			});
		}
	}
	
	function selectContentType(){
		var contentType=$("#contentType").val();
		if(contentType=="02"){
			$("#tr_originalPrice").show();
			$("#tr_nowPrice").show();
		}else{
			$("#tr_originalPrice").hide();
			$("#tr_nowPrice").hide();
		}
	}
	
	function selectByContentType(){
		var contentType=$("#content_type_query").val();
		var radioApp = $(":radio[name='RadioGroup'][checked]").val();
		$("#content_detail").load("contentList.cms?contentType="+contentType+"&radioApp="+radioApp);
	}
	function selectByContentLight(){
		var contentType=$("#content_Light_query").val();
		var radioApp = $(":radio[name='RadioGroup'][checked]").val();
		$("#content_detail").load("contentList.cms?contentType="+contentType+"&radioApp="+radioApp);
	}
	function selectByContentPoll(){
		var contentType=$("#content_poll_query").val();
		var radioApp = $(":radio[name='RadioGroup'][checked]").val();
		$("#content_detail").load("contentList.cms?contentType="+contentType+"&radioApp="+radioApp,function(){
			$("#content_poll_query").val(contentType);
		});
	}
	function showAddContent(){
		$("#div_postContent").show();
		$("#title").val("");
		$("#body").val("");
		$("#originalPrice").val("");
		$("#nowPrice").val("");
		$("#contentId").val("");
		$("#btnPostContent").val("添加");
	}
	function seeAppType(){
		//alert("11111111");
		var radioApp = $(":radio[name='RadioGroup'][checked]").val();
		if(radioApp=="01"){
			$("#light_type").hide();
			$("#spring_type").show();
			$("#contentLight").hide();
			$("#contentType").show();
			$("#poll_type").hide();
			$("#contentPoll").hide();
		}else if(radioApp=="02"){
			$("#spring_type").hide();
			$("#light_type").show();
			$("#contentLight").show();
			$("#contentType").hide();
			$("#poll_type").hide();
			$("#contentPoll").hide();
		}else if(radioApp=="03"){
			$("#poll_type").show();
			$("#contentPoll").show();
			$("#light_type").hide();
			$("#spring_type").hide();
			$("#contentType").hide();
			$("#contentLight").hide();
		}
	}
</script>

<div id="div_voteList">
	<a href="javascript:void(0);" onclick="showAddContent();">添加</a>
	<br>
		<div>	
			    <%-- <label>
					<input type="radio" name="RadioGroup" value="01" id="RadioGroup1_0" onclick="seeAppType();" <c:if test="${radioApp=='01'}">checked="checked"</c:if>/>温泉季
			     </label> --%>
			    <label>
					<input type="radio" name="RadioGroup" value="02" id="RadioGroup1_0" onclick="seeAppType();" <c:if test="${radioApp=='02'}">checked="checked"</c:if>/>灯会
			    </label>
			    <label>
					<input type="radio" name="RadioGroup" value="03" id="RadioGroup1_0" onclick="seeAppType();" <c:if test="${radioApp=='03'}">checked="checked"</c:if>/>投票
			    </label>
		</div>
	
	<hr>
			<div id="spring_type" style="display: none;">
					选择分类：<select id="content_type_query" onchange="selectByContentType();">
							<option value="01">温泉季精彩看点</option>
							<option value="02">温泉简介</option>
							<option value="03">合作商家优惠</option>
							<option value="04">温泉季合作商家展示</option>
					        </select>
			</div>
			<div id="light_type" style="display: none;">
					选择分类：<select id="content_Light_query" onchange="selectByContentLight();">
							<option value="01">灯会精彩看点</option>
							<option value="04">灯会合作商家展示</option>
							<option value="05">灯会扫描</option>
							<option value="06">服务指南</option>
					        </select>
			</div>
			<div id="poll_type" style="display: none;">
					选择分类：<select id="content_poll_query" onchange="selectByContentPoll();">
							<option value="01">活动介绍</option>
							<option value="02">最新消息</option>
							<option value="03">抽奖规则奖品展示</option>
					        </select>
			</div>
			<table border="1">
				<tr>
					<td style="color: red;">应用</td>
					<td>ID</td>
					<td>分类</td>
					<td>标题</td>
					<td>图片</td>
					<td>功能</td>
				</tr>
				<c:forEach items="${contentList}" var="content">
					<tr>
						<td>
							<c:if test="${content.app=='01'}">温泉季</c:if>
							<c:if test="${content.app=='02'}">灯会</c:if>
							<c:if test="${content.app=='03'}">投票</c:if>
						</td>
						<td>${content.identifier}</td>
						<td>${content.contentType}</td>
						<td>${content.title}</td>
						<td><img src="${content.picUrl}" width="50" height="50"/></td>
						<td>
							<a href="javascript:void(0)"onclick="showModifyContent('${content.identifier }');">修改</a>
							<a href="javascript:void(0)"onclick="addContentSort('${content.identifier }','${content.sort }');">上移</a>
							<a href="javascript:void(0)"onclick="downContentSort('${content.identifier }','${content.sort }');">下移</a>
							<a href="javascript:void(0)"onclick="delContent('${content.identifier }','${content.sort }');">删除</a>
						</td>
					</tr>
				</c:forEach>
			</table>
			<div id="pager" class="h_page">
				分页
			</div>
	<hr>
			<div id="div_postContent" style="display: none;">
				<input type="hidden" id="contentId"/>
				<table border="1">
					<%-- <tr>
						<td style="color: red;">应用</td>
						<td>
								<select id="contentApp">
									<option value="01"<c:if test="${radioApp=='01'}">selected="selected"</c:if>>温泉季</option>
									<option value="02"<c:if test="${radioApp=='02'}">selected="selected"</c:if>>灯会</option>
								</select>
						</td>
					</tr> --%>
					<tr>
						<td>分类</td>
						<td>
									<select id="contentType" onchange="selectContentType();" style="display: none;">
											<option value="01">温泉季精彩看点</option>
											<option value="02">温泉简介</option>
											<option value="03">温泉季合作商家优惠</option>
											<option value="04">温泉季合作商家展示</option>
									</select>
									<select id="contentLight" style="display: none;">
											<option value="01">灯会精彩看点</option>
											<option value="04">灯会合作商家展示</option>
											<option value="05">灯会扫描</option>
											<option value="06">服务指南</option>
									</select>
									<select id="contentPoll" style="display: none;">
											<option value="">请选择</option>
											<option value="01">活动介绍</option>
											<option value="02">最新消息</option>
											<option value="03">抽奖规则奖品展示</option>
									</select>
								
						</td>
					</tr>
					<tr>
						<td>标题</td><td><input type="text" id="title"/></td>
					</tr>
					<tr>
						<td>内容</td><td><textarea id="body" name="body"></textarea></td>
					</tr>
					<tr>
						<td>图片</td>
						<td>
							<form id="content_upload_img_form" enctype="multipart/form-data"method="post" action="contentUploadImg.cms">
								<input type="file" id="uploadImgContent" name="uploadImgContent" onchange="contentUploadImg();return false;">
							</form>
								<input type="hidden" id="picUrl"/>
						</td>
					</tr>
					<tr id="tr_originalPrice" style="display: none;">
						<td>原价</td><td><input type="text" id="originalPrice"/></td>
					</tr>
					<tr id="tr_nowPrice" style="display: none;">
						<td>现价</td><td><input type="text" id="nowPrice"/></td>
					</tr>
					<tr align="center">
						<td colspan="2"><input id="btnPostContent" type="button" value="添加" onclick="postContent();"/>
						</td>
					</tr>
				</table>
			</div>
</div>
